// Task.cpp

#include <string>
#include <sstream>
#include "Task.h"

Task::Task() {
	_completeStatus = false;
}

Task::Task(Task& taskToCopy){
	setTask(taskToCopy.getCompleteStatus(), 
			taskToCopy.getTaskDesc(), 
			taskToCopy.getStartTime(), 
			taskToCopy.getEndTime(), 
			taskToCopy.getDay(), 
			taskToCopy.getMonth(), 
			taskToCopy.getYear());
}

Task::~Task(){
	//Destructor I write later or something
}

void Task::setTask(bool status, std::string taskDesc, int startTime, int endTime, int dd, int mm, int yy = 14) {
	setCompleteStatus(status);
	setTaskDesc(taskDesc);
	setStartTime(startTime);
	setEndTime(endTime);
	setEndDate(dd, mm, yy);
}

// this function is for converting a storage to a task
void Task::convertStringToTask(std::istringstream& input) {
	std::string taskDesc;
	int startTime;
	int endTime;
	int dd;
	int mm;
	int yy;
	char dummy;
	bool completeStatus;
	input >> completeStatus;
	input >> dummy; // remove whitespace
	input >> startTime;
	input >> dummy; // remove whitespace
	input >> endTime;
	input >> dummy; // remove whitespace
	input >> dd;
	input >> dummy; // remove whitespace
	input >> mm;
	input >> dummy; // remove whitespace
	input >> yy;
	input >> dummy; // remove whitespace
	std::getline(input, taskDesc);
	setTask(completeStatus, taskDesc, startTime, endTime, dd, mm, yy);
}


void Task::setTaskDesc(std::string taskDesc) {
	_taskDesc = taskDesc;
}

void Task::setStartTime(int startTime) {
	_startTime = startTime;
}

void Task::setEndTime(int endTime) {
	_endTime = endTime;
}

void Task::setEndDate(int dd, int mm, int yy) {
	_endDate._dd = dd;
	_endDate._mm = mm;
	_endDate._yy = yy;
}


void Task::setCompleteStatus(bool status) {
	if(status && _completeStatus == false) {
	_completeStatus = true;
	}
}

std::string Task::getTaskDesc() {
	return _taskDesc;
}

int Task::getStartTime() {
	return _startTime;
}

int Task::getEndTime() {
	return _endTime;
}

bool Task::getCompleteStatus() {
	return _completeStatus;
}

int Task::getDay() {
	return _endDate._dd;
}

int Task::getMonth() {
	return _endDate._mm;
}

int Task::getYear() {
	return _endDate._yy;
}

// this function is for the writing to a storage txt
std::string Task::convertToString() {
	std::ostringstream output;
	output << getCompleteStatus() << " ";
	output << getStartTime() << " ";
	output << getEndTime() << " ";
	output << getDay() << " ";
	output << getMonth() << " ";
	output << getYear() << " ";
	output << getTaskDesc() << std::endl;
	
	return output.str();
}



